package com.elite.groovy.callback

import com.fasterxml.jackson.annotation.JsonFormat

import groovy.json.*

import javax.rmi.CORBA.UtilDelegate
import java.text.SimpleDateFormat

//导入grooby的json解析api包
import java.util.Map;
import com.elite.groovy.util.EliteBean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.wisdge.utils.RandomUtils;
import com.elite.groovy.util.Util;
import net.sf.json.JSONObject;
import net.sf.json.JSONArray;
import org.json.JSONException;
import org.json.XML;
/**
 *
 * @author luper
 *
 */

public class QuotationFlag implements ServiceBackInvoke{
	public static final Log log = LogFactory.getLog(QuotationFlag.class);
	private String charset = "gbk"; //设置字符集
	private int timeout = 100000; //设置请求超时时间
	private int enableSSLflag = 1;
	private String casecharset = "utf-8";
	private int caseenableSSLflag = 1;

	public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response){
		log.debug("-----QuotationFlag Begin Systeam----------");
		response.setHeader("Content-type", "text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		Util u = new Util();
		String requestJSONStr =u.getRequestBody(request, "UTF-8");
		log.debug("requestJSONStr:" + requestJSONStr);


		eliteBean.update("insert into INTERFACE_JSONBODY values(sysdate,'8099', 'QuotationFlag','"+requestJSONStr.toString()+"',sysdate,null)","dataSource");

	  
		JSONObject json  = new JSONObject().fromObject(requestJSONStr);
		
		String isquotation = json.getString("isquotation"); //报价标识
		String premium = json.getString("premium"); //保费
		String oldpolicy = json.getString("oldpolicy"); //上年保单号


		if(isquotation == null || isquotation=='') {
			JSONObject jsonALL3 = new JSONObject();
			jsonALL3.put("retCode", "-1");
			jsonALL3.put("retMessage", "报价标识不能为空！");
			return jsonALL3;
		}
		if(premium == null || premium=='') {
			JSONObject jsonALL3 = new JSONObject();
			jsonALL3.put("retCode", "-1");
			jsonALL3.put("retMessage", "保费不能为空！");
			return jsonALL3;
		}
		if(oldpolicy == null || oldpolicy=='') {
			JSONObject jsonALL3 = new JSONObject();
			jsonALL3.put("retCode", "-1");
			jsonALL3.put("retMessage", "上年保单号不能为空！");
			return jsonALL3;
		}


		def querysql11="select e.objective_guid from tabc_xb_case t left join elitetask e on e.elitetask_guid = t.elitetask_guid  where t.policyno = '"+oldpolicy+"'and rownum=1 ";
		def list11=eliteBean.chaxun_sql(querysql11,"dataSource");
		if(list11.size<=0){
			JSONObject jsonALL3 = new JSONObject();
			jsonALL3.put("retCode", "-1");
			jsonALL3.put("retMessage", "续保任务不存在！");
			return jsonALL3;
		
		}else{
			def map11=list11[0];
			def objective_guid=map11.get("objective_guid");
			log.debug("objective_guid-------------------------------"+objective_guid);
			
			//这里复用objective表的SEATNUM-报价标识，oarandom保费
			def updatesql3="update objective set  SEATNUM ='"+isquotation+"' , oarandom = '"+premium+"' where objective_guid ='"+objective_guid+"'";
            def updatesqlresult3=eliteBean.update(updatesql3,"dataSource");
            log.debug("updatesqlresult3:"+updatesqlresult3);
			
			JSONObject jsonALL3 = new JSONObject();
			jsonALL3.put("retCode", "1");
			jsonALL3.put("retMessage", "success");
			return jsonALL3;
		}
		
		
		

	}
}
